#ifndef LIBACCENT_UTILITY_TAG_FUNCTIONS_HPP
#define LIBACCENT_UTILITY_TAG_FUNCTIONS_HPP

#include "accent/core.hpp"
#include <type_traits>

namespace accent
{
  namespace support
  {
    namespace detail
    {
      template <typename A, typename... Bs>
      struct minimum_tag_impl;

      template <typename A>
      struct minimum_tag_impl<A>
      {
        using type = A;
      };

      template <typename A, typename B>
      struct minimum_tag_impl<A, B>
      {
        using type = typename std::conditional<std::is_base_of<A, B>::value,
                                               A, B>::type;
      };

      template <typename A, typename B, typename... Bs>
      struct minimum_tag_impl<A, B, Bs...>
      {
        using type = typename minimum_tag_impl<
                                typename minimum_tag_impl<A, B>::type,
                                Bs...>::type;
      };
    }

    template <typename A, typename... Bs>
    using minimum_tag = typename detail::minimum_tag_impl<A, Bs...>::type;
  }
}

#endif
